﻿using FS.Common.DotNetCode;
using FS.Common.DotNetUI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI.WebControls;
using FS.Web.UserControl;
using FS.Business;

namespace FS.Web.BLL.Visa_Base
{
    public partial class Base_sysparmList :  PageBase
    {
        private visa_dao _visa = new visa_dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.PageControl1.pageHandler += new EventHandler(this.pager_PageChanged);
            if (!base.IsPostBack)
            {
            }
        }
        protected void pager_PageChanged(object sender, EventArgs e)
        {
            this.DataBindGrid();
        }
        private void DataBindGrid()
        {
            int count = 0;
            if (this.Hchange.Value == "1")
            {
                this.PageControl1.PageIndex = 1;
                this.Hchange.Value = "0";
            }
            StringBuilder SqlWhere = new StringBuilder();
            IList<SqlParam> IList_param = new List<SqlParam>();          
            string ls_search = this.txt_Search.Value.Trim();
            if (!string.IsNullOrEmpty(ls_search))
            {       
                SqlWhere.Append(" and b.property_value like  @obj ");                
                IList_param.Add(new SqlParam("@obj", '%' + ls_search + '%'));
            }
            DataTable dt = _visa.GetSysParmInfoPage(SqlWhere, IList_param,this.PageControl1.PageIndex, this.PageControl1.PageSize, ref count);

            ControlBindHelper.BindRepeaterList(dt, this.rp_Item);
            this.PageControl1.SetPageCount(count); 
        }
        protected void rp_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label lblProperty_Type = e.Item.FindControl("lblProperty_Type") as Label;
                if (lblProperty_Type != null)
                {
                    using (DataTable dt = _visa.GetSelect_Sysparm())
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            string textProperty_Type = lblProperty_Type.Text;
                            textProperty_Type = textProperty_Type.Replace(dr["property_key"].ToString(), dr["property_value"].ToString());
                            lblProperty_Type.Text = textProperty_Type;
                        }
                    }
                }
            }
        }

        protected void lbtSearch_Click(object sender, EventArgs e)
        {
            this.DataBindGrid();
        }
    }
}